var MessageBox = wpf.System.Windows.MessageBox
var Grid = wpf.System.Windows.Controls.Grid
var RowDefinition = wpf.System.Windows.Controls.RowDefinition
var GridLength = wpf.System.Windows.GridLength
var StackPanel = wpf.System.Windows.Controls.StackPanel
var Orientation = wpf.System.Windows.Controls.Orientation
var HorizontalAlignment = wpf.System.Windows.HorizontalAlignment
var VerticalAlignment = wpf.System.Windows.VerticalAlignment
var TextBlock = wpf.System.Windows.Controls.TextBlock
var SolidColorBrush = wpf.System.Windows.Media.SolidColorBrush
var Color = wpf.System.Windows.Media.Color
var FontWeights = wpf.System.Windows.FontWeights
var Thickness = wpf.System.Windows.Thickness;

/**
 * 主方法
 * 
 * 唯一对外暴露的方法，转换成C#的Task执行
 */
(async function () {
    try {
        InitializeComponent()


        // env.Aliphant.UI.Forms.TestClass.GetObj(local.onClose)
        // MessageShow(local.onClose)
        local.OnClose.connect(() => {
            // env.Aliphant.UI.Forms.TestClass.GetObj(local.OnClose)
            MessageBox.Show("Hi Hi Hi")
        })

        // local.Close()


        // local.OnClose = function () {
        //     MessageBox.Show("关闭")
        // }
    }
    catch (error) {
        MessageBox.Show(error.toString())
    }
})()

function InitializeComponent() {
    // UI
    var grid = new Grid()
    var row1 = new RowDefinition()
    row1.Height = GridLength.Auto
    var row2 = new RowDefinition()
    row2.Height = GridLength.Auto

    grid.RowDefinitions.Add(row1)
    grid.RowDefinitions.Add(row2)

    var stackPanel = new StackPanel()
    stackPanel.Orientation = Orientation.Horizontal
    stackPanel.HorizontalAlignment = HorizontalAlignment.Center

    // color
    var color = Color.FromArgb(255, 255, 255, 255)

    // hour
    var hour = new TextBlock()
    hour.Text = "10"
    hour.Foreground = new SolidColorBrush(color)
    hour.FontSize = 38
    hour.FontWeight = FontWeights.Bold
    hour.VerticalAlignment = VerticalAlignment.Center
    stackPanel.Children.Add(hour)

    // 冒号1
    var mh1 = new TextBlock()
    mh1.Text = ":"
    mh1.Foreground = new SolidColorBrush(color)
    mh1.FontSize = 34
    mh1.FontWeight = FontWeights.Bold
    mh1.VerticalAlignment = VerticalAlignment.Top
    mh1.Margin = new Thickness(5, 0, 5, 0)
    stackPanel.Children.Add(mh1)

    // minute
    var minute = new TextBlock()
    minute.Text = "28"
    minute.Foreground = new SolidColorBrush(color)
    minute.FontSize = 38
    minute.FontWeight = FontWeights.Bold
    minute.VerticalAlignment = VerticalAlignment.Center
    stackPanel.Children.Add(minute)

    // 冒号2
    var mh2 = new TextBlock()
    mh2.Text = ":"
    mh2.Foreground = new SolidColorBrush(color)
    mh2.FontSize = 34
    mh2.FontWeight = FontWeights.Bold
    mh2.VerticalAlignment = VerticalAlignment.Top
    mh2.Margin = new Thickness(5, 0, 5, 0)
    stackPanel.Children.Add(mh2)

    // hour
    var second = new TextBlock()
    second.Text = "04"
    second.Foreground = new SolidColorBrush(color)
    second.FontSize = 38
    second.FontWeight = FontWeights.Bold
    second.VerticalAlignment = VerticalAlignment.Center
    stackPanel.Children.Add(second)

    grid.Children.Add(stackPanel)
    findName("main").Content = grid
}

function findName(name) {
    return local.FindName(name)
}

function MessageShow(obj) {
    MessageBox.Show(obj.ToString())
}